import { get } from 'lodash-es'
import { Name } from '@/api/name/types'

export class MemberCard {
  id?: string
  hotel_id?: string
  name_id?: string
  uid?: string
  member_number?: string
  transaction_password?: string
  end_date?: string | Date
  long_term?: boolean
  member_level_id?: string
  member_type_id?: string
  card_type?: 'Virtual' | 'Physical'
  credit?: number
  debit?: number
  balance?: number
  discount_rate?: number
  status?: string
  saler_id?: string
  reference?: string
  created_id?: string
  updated_id?: string
  created_at?: string
  updated_at?: string
  name?: Name
  version?: number;
  [key: string]: any

  constructor(data?: MemberCard) {
    this.init(data)
  }
}

MemberCard.prototype.init = function init(data?: MemberCard) {
  this.id = get(data, 'id')
  this.hotel_id = get(data, 'hotel_id')
  this.name_id = get(data, 'name_id')
  this.uid = get(data, 'uid')
  this.member_number = get(data, 'member_number')
  this.transaction_password = get(data, 'transaction_password')
  this.end_date = get(data, 'end_date')
  this.long_term = get(data, 'long_term', false)
  this.member_level_id = get(data, 'member_level_id')
  this.member_type_id = get(data, 'member_type_id')
  this.card_type = get(data, 'card_type', 'Physical')
  this.credit = get(data, 'credit', 0)
  this.debit = get(data, 'debit', 0)
  this.balance = get(data, 'balance', 0)
  this.discount_rate = get(data, 'discount_rate', 0)
  this.status = get(data, 'status')
  this.saler_id = get(data, 'saler_id')
  this.reference = get(data, 'reference')
  this.created_id = get(data, 'created_id')
  this.updated_id = get(data, 'updated_id')
  this.created_at = get(data, 'created_at')
  this.updated_at = get(data, 'updated_id')
  this.version = get(data, 'version')
  this.name = get(data, 'name')
}
